<template>
  <el-card class="box-card">
  <div slot="header" class="clearfix">
    <span>消息中心</span>
    <el-button style="float: right;" type="primary" round size="medium" @click="allRead()">全部已读</el-button>
  </div>
   <div v-for="(list,index) in msgLists" :key="index" class="text" style="line-height:0px">
      <div class="left">
        <h4 style="margin:10px 0 5px 0">{{list.title}}</h4>
        <p>{{list.content}}</p>
      </div>
      <el-badge is-dot :hidden="list.read?true:false">
        <el-button
          type="primary"
          round size="medium"
           @click="readMsg(index)"
           :disabled="list.read?true:false"
        >
        点击已读
        </el-button>
      </el-badge>
    <el-button type="danger" style="height:35px" round size="medium" @click="delMsg(index)">点击删除</el-button>
  </div>
</el-card>
</template>

<script>
import { mapState, mapMutations } from 'vuex'
export default {
  data () {
    return {
    }
  },
  computed: {
    ...mapState(['msgLists'])
  },
  methods: {
    // 点击全部已读
    allRead () {
      this.READ_ALL()
    },
    // 点击删除
    delMsg (index) {
      this.DEL_MSG(index)
    },
    // 点击已读
    readMsg (index) {
      this.READ_MSG(index)
    },
    ...mapMutations(['READ_ALL', 'DEL_MSG', 'READ_MSG'])
  }

}
</script>

<style lang="less" scoped>
/deep/.el-card__header{
  padding: 10px;
  .clearfix{
    line-height:60px;
    text-align: left;
    button{
      padding:12px;
      margin-top:10px;
    }
  }
}
/deep/.el-card__body{
  padding:20px 10px 10px 10px;
}
.text{
  display: flex;
  height:50px;
  padding:15px 0;
  border-bottom:1px solid #eee;
  .left{
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    flex: 1;
    text-align: left;
  }
}
</style>
